<!doctype html>
<html>
<head>
    <meta charset="UTF-8">
    <title>跑帮郎</title>
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    {include file="public/resource"/}
</head>
    <style>
        .card{
            width: 95%;
            height: 185px;
            margin: 15px auto;
            border-radius: 10px;
            background: #fff;
        }
        .address-div{
            height: 40px;
            line-height: 40px;
            padding-left: 25px;
            overflow: hidden;
        }
        .address{
            color: #999;
        }
        .line{
            color: #000;
            min-height: 50px;
            line-height: 50px;
            padding-left: 15px;
            border-bottom: 1px solid #e5e5e5;
        }
    </style>
<body>
    <header class="mui-bar mui-bar-nav" id="title_bar">
        <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
        <h1 class="mui-title">发单列表</h1>
    </header>
    <div class="mui-content">
        <span id="list"></span>
    </div>
    <script>
        var token = localStorage.getItem('token');
        function get_status(val) {
            switch (val){
                case 1:
                    return "{:lang('label')['order_status_1']}";
                break;
                case 2:
                    return "{:lang('label')['order_status_2']}";
                break;
                case 3:
                    return "{:lang('label')['order_status_3']}";
                break;
                case 4:
                    return "{:lang('label')['order_status_4']}";
                break;
                case 5:
                    return "{:lang('label')['order_status_5']}";
                break;
                case 6:
                    return "{:lang('label')['order_status_6']}";
                break;
                case 7:
                    return "{:lang('label')['order_status_7']}";
                break;
            }
        }
        $.ajax(domain+'app/user/get_send_order_list?token='+token,{
            success:function (json) {
                var data = json.data;
                for(var i in data){
                    if(data[i].type == 'shop_for_me'){
                        var type = '帮买';
                        var status = get_status(data[i].status);
                        if(status == '待支付'){
                            var disabled = '支付并发布';
                            var color = 'orange';
                            var style = '';
                        }else{
                            var disabled = status;
                            var color = '#999';
                            var style = 'disabled';
                        }
                        if(data[i].place_lat == '' || data[i].place_lat == 0){
                            place = '随意';
                        }else{
                            place = data[i].place_name+' '+data[i].place_address;
                        }
                        document.getElementById('list').innerHTML += '<div class="card"> <div class="line"> <div class="mui-btn" style="margin-top: 10px;background: #09f;color: #fff;border: none;">'+type+'</div> <div style="float: right;margin-right: 10px;color: #999">￥'+data[i].price+'</div> </div> <div class="line" onclick="show_detail('+data[i].order_id+')"> <div class="address-div">出发地：<span class="address">'+place+'</span></div> <div class="address-div">目的地：<span class="address">'+data[i].target_name+' '+data[i].target_address+'</span></div> </div> <div onclick="pay('+data[i].order_id+','+data[i].status+')" class="mui-btn mui-'+style+'" style="width: 70%; margin: 0 auto;display: block;margin-top:8px;border-color:'+color+';color:'+color+';" name="'+name+'">'+disabled+'</div> </div>';
                    }
                }
            }
        });

        function show_detail(order_id) {
            location = '__URL__/order_detail?order_id='+order_id;
        }

        function pay(order_id,status) {
            if(status == 1){
                //调微信支付
                $.ajax(domain+'app/user/order_pay?type=wxpay&token='+token+'&order_id='+order_id,{
                    success:function (json) {
                        var data = JSON.stringify(json.data);
                        /*var url = "wxpay?appId=" + info.appId + "&timeStamp=" +info.timeStamp + "&nonceStr=" + info.nonceStr +
                         "&pg=" +info.pg + "&signType=" +info.signType + "&paySign=" +info.paySign;
                         location = url + "&showwxpaytitle=1";*/
                        WeixinJSBridge.invoke(
                            'getBrandWCPayRequest',
                            {
                                data
                            },
                            function(res){
                                alert(res.err_msg)
//                                if(res.err_msg == "get_brand_wcpay_request:ok" ) {
                                    $.ajax(domain+'app/user/pay_next?token='+token+'&order_id='+order_id+'&pay=wxpay',{
                                        success:function (json) {
                                            layer.open({
                                                content: '支付成功',
                                                skin: json.msg,
                                                time: 2 //2秒后自动关闭
                                            });
                                        }
                                    })
//                                }
                            }
                        );
                    }
                })
            }

        }


    </script>
</body>
</html>